!/bin/bash
port_array=(22 80 8080 3306 8085)
service_array=(ssh nginx jenkins mysql spug )

for(( i=0;i<${#port_array[@]};i++)) do
	    time=$(date "+%Y-%m-%d %H:%M:%S")
	        port=${port_array[i]};
		    service_name=${service_array[i]};
		        port_status=`netstat -nlt|grep ${port_array[i]}|wc -l`
			    service_process_num=`pgrep -l $service_name | wc -l`
			     
	 if [ $port_status -lt 1 ]
	   then
	    echo -e "\033[32m[未占用] $time $service_process_num $service_name:$port\033[0m"
	   else
	    echo -e "\033[31m[已占用] $time $service_process_num $service_name:$port\033[0m"
	fi
done;
